home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / BETEDIT.ZIP / DIALOG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-16  |  6.0 KB  |  164 lines

  1. /**************************************************************************
  2. *                                                                         *
  3. *   MODULE :  dialog.cpp                                                  *
  4. *                                                                         *
  5. *   Purpose:  Dialog demonstrating use of Betedit                         *
  6. *                                                                         *
  7. *  Comments:  Only demo code - not enough to build this ..                *
  8. *                                                                         *
  9. *   History:  Date      Reason                                            *
  10. *             --------  -----------------------------------               *
  11. *                                                                         *
  12. *             10/06/92  Created                                           *
  13. *                                                                         *
  14. **************************************************************************/
  15.  
  16.  
  17. #include <afxwin.h>                /* required for all Windows applications */
  18. #include "dialog.h"
  19.  
  20.  
  21. BEGIN_MESSAGE_MAP( CObViewDlg, CModalDialog)
  22.     ON_WM_PARENTNOTIFY()
  23.     ON_WM_ACTIVATEAPP()
  24.     ON_MESSAGE(BEM_NOTVALID, OnNotValid)
  25. END_MESSAGE_MAP()
  26.  
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. //
  30. // Constructor with parameters
  31. // Calls base class constructor and saves the parameters for use
  32. //
  33. CObViewDlg::CObViewDlg(float* pYMax, float* pYMin, char* szTitle, CWnd* pParentWnd)
  34.     : CModalDialog(IDD_VIEWPARAM, pParentWnd)
  35. {
  36.     m_pYMax = pYMax;
  37.     m_pYMin = pYMin;
  38.     strcpy(m_szTitle, szTitle);
  39. }
  40.  
  41.  
  42. /////////////////////////////////////////////////////////////////////////////
  43. //
  44. // OnInitDialog:
  45. // Gets everything ready for display and use - just before display
  46. //
  47. BOOL CObViewDlg::OnInitDialog()
  48. {
  49.     SetWindowText(m_szTitle);                             // Get the title OK
  50.  
  51. // We have to set up our better edits as subclassed controls
  52.     VERIFY(m_YMaxEdit.SubclassEdit(IDC_YAXMAX, this, -1000, 1000));  // Upper value
  53.     m_YMaxEdit.SetValue(*m_pYMax);
  54.     VERIFY(m_YMinEdit.SubclassEdit(IDC_YAXMIN, this, -1000, 1000));
  55.     m_YMinEdit.SetValue(*m_pYMin);
  56.  
  57. // Set validation override off
  58.     m_bOverride = FALSE;
  59.     return TRUE;
  60. }
  61.  
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64. //
  65. // OnActivateApp : Notification of task switching.
  66. // We prevent validation of the contents of the controls when the
  67. // user switches to another app, and enable when switching back.
  68. //
  69. afx_msg void CObViewDlg::OnActivateApp(BOOL bActive, HANDLE hTask)
  70. {
  71.     m_bOverride = !bActive;          // Prevent activity when app deactivated
  72. }
  73.  
  74.  
  75. /////////////////////////////////////////////////////////////////////////////
  76. //
  77. // OnParentNotify : Notification of an action to child window.
  78. // We dont want to validate the contents of the controls when
  79. // the user presses the CANCEL button, so test for this.
  80. //
  81. afx_msg void CObViewDlg::OnParentNotify(UINT wParam, LONG lParam)
  82. {
  83.     CPoint  thePoint(LOWORD(lParam), HIWORD(lParam));        // Click co-ords
  84.  
  85.     if ((wParam == WM_LBUTTONDOWN) &&
  86.         (ChildWindowFromPoint(thePoint) == GetDlgItem(IDCANCEL)))
  87.         m_bOverride = TRUE;                   // Flag that cancel was pressed
  88. }
  89.  
  90.  
  91. /////////////////////////////////////////////////////////////////////////////
  92. //
  93. // OnNotValid : A control is invalid - give a message and retain focus
  94. // We use a separate message for this as this allows a delayed action
  95. // by using PostMessage - ensures changes in focus are over. Note that
  96. // we temporarily override validation while in this routine, in some
  97. // circumstances (user pressed Enter to select OK) this routine can provoke
  98. // extra validation messages via the BetEdit KillFocus checks!
  99. //
  100. afx_msg LONG CObViewDlg::OnNotValid(UINT wParam, LONG lParam)
  101. {
  102.     if (!m_bOverride)             // Only do something if the override is off
  103.     {
  104.         CWnd*   pWnd = GetDlgItem(wParam);          // Control with a problem
  105.  
  106.         m_bOverride = TRUE;                       // and override temporarily
  107.         pWnd->SendMessage(BEM_VALIDATE, 1, 0);    // Display an error message
  108.         pWnd->SetFocus();                                 // Retain the focus
  109.         pWnd->SendMessage(EM_SETSEL, 0, 0x7FFF);                // Select all
  110.         m_bOverride = FALSE;                        // Restore previous state
  111.     }
  112.     return 1;
  113. }
  114.  
  115.  
  116. /////////////////////////////////////////////////////////////////////////////
  117. //
  118. // OnOK:
  119. // User has accepted data, return the results. Note that this relies
  120. // upon the saved pointer still being valid - users take note !
  121. //
  122. void CObViewDlg::OnOK()
  123. {
  124.     float       fMax, fMin;
  125.  
  126.     if (m_YMaxEdit.SendMessage(BEM_VALIDATE, 0, 0) == 0) // Check upper value
  127.     {
  128.         SendMessage(BEM_NOTVALID, IDC_YAXMAX, 0);
  129.         return;
  130.     }
  131.     if (m_YMinEdit.SendMessage(BEM_VALIDATE, 0, 0) == 0) // Check upper value
  132.     {
  133.         SendMessage(BEM_NOTVALID, IDC_YAXMIN, 0);
  134.         return;
  135.     }
  136.     fMax = m_YMaxEdit.GetValue();                  // Get value as float
  137.     fMin = m_YMinEdit.GetValue();
  138.     if (fMax != fMin)
  139.     {
  140.         *m_pYMax = fMax;
  141.         *m_pYMin = fMin;
  142.     }
  143.     else
  144.     {
  145.         MessageBox("Upper and lower values must be different", "Bad axes limits", MB_ICONEXCLAMATION);
  146.         CWnd*   pWnd = GetDlgItem(IDC_YAXMAX);      // Control with a problem
  147.         pWnd->SetFocus();                                 // Retain the focus
  148.         pWnd->SendMessage(EM_SETSEL, 0, 0x7FFF);                // Select all
  149.         return;
  150.     }
  151.     EndDialog(IDOK);                                /* Exits the dialog box */
  152. }
  153.  
  154.  
  155. /////////////////////////////////////////////////////////////////////////////
  156. //
  157. // OnCancel:
  158. // User has given up - do likewise
  159. //
  160. void CObViewDlg::OnCancel()
  161. {
  162.     EndDialog(IDCANCEL);
  163. }
  164.